<template>
  <div>
    <div style="display: flex">
      <div style="width: 20%">
        楼主：{{postObj.user.username}}<br>
        <img :src="postObj.user.face" width="50" height="50">
        注册日期：{{postObj.user.regDate}}
      </div>
      <div>
        主题：{{postObj.title}} @ {{postObj.time}}<br>
        {{postObj.content}}
      </div>
    </div>
    回帖：
    <table border="1px" width="100%" cellspacing="1">
      <thead>
      <tr>
        <th>主题</th>
        <th>作者</th>
        <th>内容</th>
        <th>回帖时间</th>
      </tr>
      </thead>
      <tbody>
      <tr v-for="r in postObj.replayList" :key="r.id">
        <td>{{r.title}}</td>
        <td>{{r.user.username}}</td>
        <td>{{r.content}}</td>
        <td>{{r.time}}</td>
      </tr>
      </tbody>
    </table>
    回复帖子<br>
    标题：<input v-model="newReplay.title"><br>
    内容：<textarea v-model="newReplay.content"></textarea><br>
    <input type="button" value="发表" @click="addReplay()">
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      postObj:{},
      newReplay:{}
    }
  },created(){
    this.postObj.id=this.newReplay.postId = this.$route.query.postId;
    this.init();
  }, methods: {
    init() {
      axios.get("/project/post/findById", {
        params: this.postObj
      }).then(resp => {
        this.postObj=resp.data;
        this.postObj.user.face="/project/face/" + this.postObj.user.face;
      })
    },

    addReplay() {
      axios.get("/project/replay/add", {
        params: this.newReplay
      }).then(resp => {
        if (resp.data == "ok") {
          location.href = "/replay?postId=" + this.postObj.id;
        }
      })
    }
  }
}
</script>

<style scoped>

</style>